cmake_minimum_required(VERSION 2.8)
#set project name
project(TYEarth)

#find osg
find_path(OSG_ROOT PATHS "${OSG_ROOT}"  "$ENV{OSG_ROOT}")

# source_group working
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
#find files
file(GLOB header_files include/*.h)
file(GLOB source_files src/*.cpp)
file(GLOB ui_files ui/*.ui)
file(GLOB qrc_files res/*.qrc)

#add files to project
source_group("Header Files" FILES ${header_files})
source_group("Source Files" FILES ${source_files})
source_group("UI Files" FILES ${ui_files})
source_group("Resource Files" FILES ${qrc_files})

#set include path
include_directories(${PROJECT_INCLUDE}/TYEarth/include)
include_directories(${QT_ROOT}/include)
include_directories(${QT_ROOT}/include/QtCore)
include_directories(${QT_ROOT}/include/QtGui)
include_directories(${QT_ROOT}/include/QtWidgets)
include_directories(${QT_ROOT}/include/QtOpenGL)
include_directories(${OSG_ROOT}/include)

#set library path
link_directories(${QT_ROOT}/lib)
link_directories(${OSG_ROOT}/lib)
link_directories(${PROJECT_INCLUDE}/Bin/Release ${PROJECT_INCLUDE}/Bin/Debug)

#set qt 
#set(CMAKE_PREFIX_PATH ${QT_ROOT})
set(CMAKE_INCLUDE_CURRENT_DIR ON)   
set(CMAKE_AUTOMOC ON) 

#set(QT_USE_QTOPENGL true)
set(QT_USE_QTGUI true)
set(QT_USE_QTWidget true)
set(QT_USE_QTCore true)

qt5_wrap_ui(TYEarth_UIC ${ui_files})
qt5_wrap_cpp(TYEarth_MOC ${header_files})


if( MSVC )
	#to get rid of the (system) console
	add_executable( ${PROJECT_NAME} WIN32 ${header_files} ${source_files} ${ui_files} ${qrc_files})
elseif( APPLE )
	add_executable( ${PROJECT_NAME} MACOSX_BUNDLE ${header_files} ${source_files} ${ui_files} ${qrc_files})
else()
	add_executable( ${PROJECT_NAME} ${header_files} ${source_files} ${ui_files} ${qrc_files})
endif()

add_definitions(-D HQ_TYEarth_LIBRARY)

#target_link_libraries(${PROJECT_NAME} debug "Qt5Cored.lib" "Qt5Guid.lib" "Qt5Widgetsd.lib" optimized "Qt5Core.lib" "Qt5Gui.lib" "Qt5Widgets.lib")
if (WIN32)
	target_link_libraries( ${PROJECT_NAME} Qt5::WinMain )
endif()
qt5_use_modules(${PROJECT_NAME} Core Gui Widgets)

set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_INCLUDE}/Bin)

#link qt library
target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES})
set_target_properties(${PROJECT_NAME} PROPERTIES AUTOMOC ON)
set_target_properties(${PROJECT_NAME} PROPERTIES FLODER "UI")

target_link_libraries(${PROJECT_NAME} debug ${OSG_ROOT}/lib/OpenThreadsd.lib optimized  ${OSG_ROOT}/lib/OpenThreads.lib)
target_link_libraries(${PROJECT_NAME} debug ${OSG_ROOT}/lib/osgd.lib optimized  ${OSG_ROOT}/lib/osg.lib)
target_link_libraries(${PROJECT_NAME} debug ${OSG_ROOT}/lib/osgDBd.lib optimized  ${OSG_ROOT}/lib/osgDB.lib)
target_link_libraries(${PROJECT_NAME} debug ${OSG_ROOT}/lib/osgFXd.lib optimized  ${OSG_ROOT}/lib/osgFX.lib)
target_link_libraries(${PROJECT_NAME} debug ${OSG_ROOT}/lib/osgGAd.lib optimized  ${OSG_ROOT}/lib/osgGA.lib)
target_link_libraries(${PROJECT_NAME} debug ${OSG_ROOT}/lib/osgUtild.lib optimized  ${OSG_ROOT}/lib/osgUtil.lib)
target_link_libraries(${PROJECT_NAME} debug ${OSG_ROOT}/lib/osgViewerd.lib optimized  ${OSG_ROOT}/lib/osgViewer.lib)
target_link_libraries(${PROJECT_NAME} debug ${OSG_ROOT}/lib/osgQtd.lib optimized  ${OSG_ROOT}/lib/osgQt.lib)
